<div class="cadredossier"><?php 
//$_REQUEST["dossierId"]=1;
$dossierId=getParameter("dossierId");

$dossier = R::load('cabinet_dossier',$dossierId);


?>
<table id="box-table-a" summary="Employee Pay Sheet">
<tr>
		<td>
				Numero de dossier :<br><input type="text" name="numeroDeDossier" value="<?=$dossier->numeroDeDossier?> " readonly  ></td>

		<td>	Nom:<br> <input type="text" name="nom" value="<?=$dossier->nom?> " readonly></td>

		<td>	Prenom :<br><input type="text" name="prenom" value="<?=$dossier->prenom?> " readonly></td>
		</td>
</tr>


<tr>
		<td>
			Adresse :<br><br><input type="text" name="adresse" value="<?=$dossier->adresse?> " readonly></td>

		<td>	Date De Naissance :<br><input type="text" name="dateDeNaissance" value="<?=$dossier->dateDeNaissance?> " readonly></td>

		<td>	Adressé Par :<br><input type="text" name="adressePar" value="<?=$dossier->adressePar?> " readonly>
		</td>
</tr>

<tr>
		<td>
			Tel  :<br><input type="text" name="Tel" value="<?=$dossier->telPortable?> ,<?=$dossier->telDomicil?> " readonly></td>

		<td>	Email :<br><input type="text" name="Email" value="<?=$dossier->email?> " readonly></td>

		<td>	Profession :<br><input type="text" name="Profession" value="<?=$dossier->profession?>" readonly> 
		</td>
</tr>

<tr>
	<td>			<?php $etat = R::load('cabinet_etatgeneral',$dossier->etatGenerale);  ?>
		    Etat Generale :<br><input type="text" name="etatGenerale" value="<?=$etat->libelle?>" readonly> </td>
			<?php $categorie = R::load('cabinet_categoriepatient',$dossier->categorie);  ?>
	<td>	Categorie :<br><input type="text" name="categorie" value="<?=$categorie->libelle?>" readonly> 
	</td>
	<td>
												<?php 

												$reste=0;

												$SQL="SELECT
												Sum(cabinet_dossier_avance.montant) as dossier_avance
												FROM
												cabinet_dossier_avance
												WHERE
												cabinet_dossier_avance.dossierId = $dossier->id";

												$rs=ew_LoadRecordset($SQL);
												if ($rs && !$rs->EOF) $dossier_avance=$rs->fields['dossier_avance'];


												$SQL="SELECT
												Sum(cabinet_soins.montant) as soins_montant
												FROM
												cabinet_soins
												WHERE
												cabinet_soins.dossierId  = $dossier->id";

												$rs=ew_LoadRecordset($SQL);



												if ($rs && !$rs->EOF) $soins_montant=$rs->fields['soins_montant'];


												$reste = $soins_montant - $dossier_avance ;

												if ($reste=="") $reste=0;
		
												?>
		Reste :<br><font color="red"><input type="text" name="categorie" value="<?=$reste?>" readonly style="background-color:red ; font-color:red"> </font>

</td>
</tr>

</table>





<table id="box-table-a" >
<tr>
				<?php
$compt = 0;
				$dossierId = getParameter("dossierId");
	if ($dossierId){ 
				$rs=ew_LoadRecordset("SELECT
											cabinet_dossier.id as id,
											cabinet_dossier.numeroDeDossier as num,
											cabinet_dossier.nom as nom,
											cabinet_dossier.prenom as prenom,
											cabinet_dossier_lien_parente.lien_parent as lien
									FROM
											cabinet_dossier_lien_parente
									INNER JOIN 
											cabinet_dossier ON cabinet_dossier_lien_parente.dossierId = cabinet_dossier.id
									WHERE
											cabinet_dossier_lien_parente.dossierIdLien   = $dossierId");

				while (!$rs->EOF)
				{  
				 
					
					?>
					
					<?php $compt++;     ?>
						 <td> <a href="/butterflyportal/?table=cabinet_soins_portlet&filter=1&dossierId=<?=$rs->fields["id"]?>" target="_blank">   <?=$rs->fields["nom"]?> <?=$rs->fields["prenom"]?> (<?=$rs->fields["lien"]?>)  </a> </td>
						<?php
						
						$var = ($compt%3 == 0);
						if($compt%3 == 0) echo "</tr>";      ?>
					
					
					<?php 
					$rs->MoveNext();
				}

				$rs=ew_LoadRecordset("SELECT
											cabinet_dossier.id as id,
											cabinet_dossier.numeroDeDossier as num,
											cabinet_dossier.nom as nom,
											cabinet_dossier.prenom as prenom,
											cabinet_dossier_lien_parente.lien_parent as lien
									FROM
											cabinet_dossier
									INNER JOIN 
											cabinet_dossier_lien_parente ON cabinet_dossier.id = cabinet_dossier_lien_parente.dossierIdLien
									WHERE
											cabinet_dossier_lien_parente.dossierId   = $dossierId");

				while (!$rs->EOF)
				{
					
					?>

					<?php $compt++;     ?>
						 <td> <a href="/butterflyportal/?table=cabinet_soins_portlet&filter=1&dossierId=<?=$rs->fields["id"]?>" target="_blank">   <?=$rs->fields["nom"]?> <?=$rs->fields["prenom"]?> (<?=$rs->fields["lien"]?>)  </a> </td>
						<?php
						
						if(  ($compt%3) == 0 ) echo "</tr>";      ?>
					
					
					
					
					<?php 
					$rs->MoveNext();
				}}?>


</table>





</div>